﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace System
{
    public class IOExtension
    {
        public static string GetNewFileName(string p)
        {
            if (File.Exists(p))
            {
                FileInfo fi = new FileInfo(p);
                string Dir = Path.GetDirectoryName(p) + '\\';
                if (Dir == "\\") Dir = "";
                string FileNameWOE = Path.GetFileNameWithoutExtension(p);
                int i = 1;
                while (File.Exists(p))
                {
                    p = "{0}{1}({2}){3}".goFormat(
                        Dir, FileNameWOE, i++, fi.Extension);
                }
            }
            return p;
        }
    }
}
